package com.fy.service;

import com.fy.commodity.api.CommodityService;
import com.fy.commodity.basedto.PageSize;
import com.fy.commodity.reqdto.*;
import com.fy.commodity.resdto.*;
import com.fy.common.util.BeansUtil;
import com.fy.entity.*;
import com.fy.mapper.CommodityMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@RequestMapping("commodity")
public class CommodityServiceImpl implements CommodityService {

    @Resource
    private CommodityMapper commodityMapper;

    @Override
    @PatchMapping(value = "queryauditlist")
    public List<CommodityListDto> queryAuditList(@NotNull PageSize pageSize) {
        List<CommodityList> commodityList = commodityMapper.queryAuditList(pageSize);
        List<CommodityListDto> commodityListDtoList = BeansUtil.listCopy(commodityList, CommodityListDto.class);
        return commodityListDtoList;
    }

    @Override
    @PatchMapping(value = "queryauditdetails")
    public CommodityDetailsDto queryAuditDetails(@NotNull Integer commodityId, @NotNull Integer shopId) {
        CommodityDetails commodityDetails = commodityMapper.queryAuditDetails(commodityId, shopId);
        CommodityDetailsDto commodityDetailsDto = new CommodityDetailsDto();
        BeanUtils.copyProperties(commodityDetailsDto, commodityDetails);
        return commodityDetailsDto;
    }

    @Override
    @PatchMapping(value = "ispass")
    public Integer isPass(@NotNull IsPassDto isPassDto) {
        IsPass isPass = new IsPass();
        BeanUtils.copyProperties(isPassDto, isPass);
        commodityMapper.isPass(isPass);
        return null;
    }

    @Override
    public List<CommodityShowDto> queryCommodityList() {
        return null;
    }

    @Override
    @PatchMapping(value = "querycommoditylist")
    public List<CommodityShowDto> queryCommodity() {
        List<CommodityShow> commodityShowList = commodityMapper.queryCommodity();
        List<CommodityShowDto> commodityShowDtoList = BeansUtil.listCopy(commodityShowList, CommodityShowDto.class);
        return commodityShowDtoList;
    }

    @Override
    @PatchMapping(value = "querycommoditylist")
    public List<CommodityShowDto> queryCommodityList(@NotNull Integer shopId) {
        List<CommodityShow> commodityShowList = commodityMapper.queryCommodityList(shopId);
        List<CommodityShowDto> commodityShowDtoList = BeansUtil.listCopy(commodityShowList, CommodityShowDto.class);
        return commodityShowDtoList;
    }

    @Override
    @PatchMapping(value = "createcommodity")
    public Integer createCommodity(@NotNull CommodityCreateDto commodityCreateDto) {
        CommodityCreate commodityCreate = new CommodityCreate();
        BeanUtils.copyProperties(commodityCreateDto, commodityCreate);
        commodityMapper.createCommodity(commodityCreate);
        return null;
    }

    @Override
    @PatchMapping(value = "updatecommodity")
    public Integer updateCommodity(@NotNull CommodityUpdateDto commodityUpdateDto) {
        CommodityUpdate commodityUpdate = new CommodityUpdate();
        BeanUtils.copyProperties(commodityUpdateDto, commodityUpdate);
        commodityMapper.updateCommodity(commodityUpdate);
        return null;
    }

    @Override
    @PatchMapping(value = "deletecommodity")
    public Integer deleteCommodity(@NotNull Integer shopId, @NotNull Integer commodityId) {
        return commodityMapper.deleteCommodity(shopId, commodityId);
    }

    @Override
    @PatchMapping(value = "querycategorylist")
    public List<CategoryDto> queryCategoryList() {
        List<Category> categoryList = commodityMapper.queryCategoryList();
        List<CategoryDto> categoryDtoList = BeansUtil.listCopy(categoryList, CategoryDto.class);
        return categoryDtoList;
    }

    @Override
    @PatchMapping(value = "createcategory")
    public Integer createCategory(@NotNull CategoryCreateDto categoryCreateDto) {
        CategoryCreate categoryCreate = new CategoryCreate();
        BeanUtils.copyProperties(categoryCreateDto, categoryCreate);
        commodityMapper.createCategory(categoryCreate);
        return null;
    }

    @Override
    @PatchMapping(value = "updatecategory")
    public Integer updateCategory(@NotNull CategoryUpdateDto categoryUpdateDto) {
        CategoryUpdate categoryUpdate = new CategoryUpdate();
        BeanUtils.copyProperties(categoryUpdateDto, categoryUpdate);
        commodityMapper.updateCategory(categoryUpdate);
        return null;
    }

    @Override
    @PatchMapping(value = "deletecategory")
    public Integer deleteCategory(@NotNull Integer categoryId) {
        return commodityMapper.deleteCategory(categoryId);
    }

    @Override
    @PatchMapping(value = "querySpecification")
    public List<SpecificationDto> querySpecification(@NotNull Integer categoryId) {
        List<Specification> specificationList = commodityMapper.querySpecification(categoryId);
        List<SpecificationDto> specificationDtoList = BeansUtil.listCopy(specificationList, SpecificationDto.class);
        return specificationDtoList;
    }

    @Override
    @PatchMapping(value = "createspecification")
    public Integer createSpecification(@NotNull SpecificationCreateDto specificationCreateDto) {
        SpecificationCreate specificationCreate = new SpecificationCreate();
        BeanUtils.copyProperties(specificationCreateDto, specificationCreate);
        commodityMapper.createSpecification(specificationCreate);
        return null;
    }

    @Override
    @PatchMapping(value = "updatespecification")
    public Integer updateSpecification(@NotNull SpecificationUpdateDto specificationUpdateDto) {
        SpecificationUpdate specificationUpdate = new SpecificationUpdate();
        BeanUtils.copyProperties(specificationUpdateDto, specificationUpdate);
        commodityMapper.updateSpecification(specificationUpdate);
        return null;
    }

    @Override
    @PatchMapping(value = "deletespecification")
    public Integer deleteSpecification(@NotNull Integer categoryId, @NotNull Integer specificationId) {
        return commodityMapper.deleteSpecification(categoryId, specificationId);
    }
}
